package com.woniuxy.cloud.starter;

import com.woniuxy.cloud.starter.context.ContextPopulateFilter;
import lombok.extern.slf4j.Slf4j;
import com.woniuxy.cloud.starter.context.openfeign.ContextInjectionFeignInterceptor;
import com.woniuxy.cloud.starter.logging.LogAspect;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

@Configuration//标记配置类
@Slf4j
@ComponentScan("com.woniuxy.cloud.starter.components")
public class TicketAutoConfiguration {
    /**
     * 注入上下文渲染过滤器，用于从请求中解析出网关下传的操作员信息
     * @return
     */
    @Bean
    public FilterRegistrationBean registerAuthFilter() {
        log.info("注入上下文渲染过滤器");
        FilterRegistrationBean registration = new FilterRegistrationBean();
        registration.setFilter(new ContextPopulateFilter());
        registration.addUrlPatterns("/*");
        registration.setName("contextPopulateFilter");
        registration.setOrder(1);  //值越小，Filter越靠前

        return registration;
    }

    /**
     * feign拦截器,用于在远程服务调用时注入上下文信息
     * @return
     */
    @Bean
    public ContextInjectionFeignInterceptor contextInjectionFeignInterceptor(){
        log.info("注入contextInjectionFeignInterceptor");
        return new ContextInjectionFeignInterceptor();
    }

    @Bean
    public LogAspect logAspect(){
        log.info("初始化日志拦截切面...");
        return new LogAspect();
    }

}
